home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / SoundAndMusic / cmix / Minc / print.c < prev    next >
C/C++ Source or Header  |  1991-03-16  |  2KB  |  110 lines

  1. #include <stdio.h>
  2. /*
  3.  * file: print.c
  4.  * 
  5.  * This file contains a function that is an internally defined function
  6.  * to print to standard output.
  7.  */
  8.  
  9. is_print(str,a,n)
  10. char *str;
  11. double  a[];
  12. int n;
  13. {
  14.     int i;
  15.     char *s;
  16.     char buf[500],*cp,c;
  17.     cp = buf;
  18.  
  19.     if (!strcmp(str,"print")|| !strcmp(str,"printf")) {
  20.  
  21.         i = (int) a[0];
  22.         s = (char *) i;
  23.  
  24.         if (n >40)  {
  25.     fprintf(stderr,"ERROR: exceeded maximum number of args to print\n");
  26.             return(1);
  27.         }
  28.  
  29.         for (i=0;s[i]!='\0';i++)  {
  30.             if (i >= 500)  {
  31. fprintf(stderr,"ERROR: exceeded maximum command string length in print\n");
  32.                 return(1);
  33.             }
  34.  
  35.             c = s[i];
  36.  
  37.             switch(c) {
  38.  
  39.             case  '\\':  
  40.                 i++;
  41.                 c = s[i];
  42.                 switch (c) {
  43.  
  44.                 case 'n': 
  45.                     *cp++ = '\n';
  46.                     break;
  47.                 case 't': 
  48.                     *cp++ = '\t';
  49.                     break;
  50.                 case '\\': 
  51.                     *cp++ = '\\';
  52.                     break;
  53.                 case '%': 
  54.                     *cp++ = '%';
  55.                     break;
  56.                 }
  57.  
  58.                 break;
  59.  
  60.             case  '%':  
  61.                 i++;
  62.                 c = s[i];
  63.                 *cp++ = '%';
  64.                 switch (c) {
  65.  
  66.                 case 'f':  
  67.                     *cp++ = 'f';
  68.                     break;
  69.                 case 'd':  
  70.                     *cp++ = 'f';
  71.                     break;
  72.                 case 'l':  
  73.                     *cp++ = 'f';
  74.                     break;
  75.                 case ' ':  
  76.                     *cp++ = 'f';
  77.                     *cp++ = ' ';
  78.                     break;
  79.                 case ',':  
  80.                     *cp++ = 'f';
  81.                     *cp++ = ',';
  82.                     break;
  83.                 }
  84.  
  85.  
  86.                 break;
  87.  
  88.  
  89.  
  90.  
  91.             default:
  92.                 *cp++ = c;
  93.                 break;
  94.             }
  95.         }
  96.  
  97.         *cp++ = '\0';
  98.  
  99.  
  100.         printf(buf,
  101.         a[  1],a[  2],a[  3],a[  4],a[  5],a[  6],a[  7],a[  9],a[ 10],
  102.         a[ 11],a[ 12],a[ 13],a[ 14],a[ 15],a[ 16],a[ 17],a[ 19],a[ 20],
  103.         a[ 21],a[ 22],a[ 23],a[ 24],a[ 25],a[ 26],a[ 27],a[ 29],a[ 30],
  104.         a[ 31],a[ 32],a[ 33],a[ 34],a[ 35],a[ 36],a[ 37],a[ 39],a[ 40]);
  105.         return(1);
  106.     }
  107.     return(0);
  108.  
  109. }
  110.